import "package:sports_new/entity/data/team_entiy.dart";
import "package:sports_new/server/http/dio_utils.dart";
import "package:sports_new/utils/user.dart";

import "../api_dir.dart";

class DataApi {
  ///关注球队选择列表
  static Future<List<FocusTeamListEntity>?> teamForSelect() async {
    final result = await DioUtils.post("/${ApiDir.data}/app-do/teamForSelect");
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<FocusTeamListEntity> data = result.data["d"]
          .map<FocusTeamListEntity>((e) => FocusTeamListEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///关注球队  1关注 2取消关注
  static Future<int?> focusTeam(int id, int isFocus) async {
    final params = {
      "addOrDel": isFocus,
      "list": [id],
      "userId": User.auth?.userId,
    };
    final result =
        await DioUtils.post("/${ApiDir.data}/app-do/teamFocusUpdate", params: params);
    if (result.statusCode == 200) {
      return result.data["c"];
    }
    return null;
  }
  
  static Future<bool> focusTeamBool(int id, bool isFocus) async => (await focusTeam(id, isFocus ? 1 : 2)) == 200;
    
}